/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Business.File;

import java.io.*;

/**
 *
 * @author Domenico
 */
public class FileFacade {

    public String ottieniTestoFile(String percorso) {
        String testo = null;
        try {
            RandomAccessFile randomaccessfile = new RandomAccessFile(new File(percorso), "r");
            
            byte[] fileb = new byte[(int)randomaccessfile.length()];
            randomaccessfile.read(fileb);
            
            testo = new String(fileb);
            randomaccessfile.close();
            
        } catch (IOException ex) {
            //ex.printStackTrace();
        }
        return testo;
    }
   
    public boolean scriviFileDiTesto(String DestinationFolder, String testo, String NomeFile)  {
        
        File dir=new File(DestinationFolder);
        if (!dir.exists())
            dir.mkdirs();
        
        File fileOutput = new File(DestinationFolder + NomeFile);
        FileOutputStream file;
        try {
            file = new FileOutputStream(fileOutput);
            PrintStream disco = new PrintStream(file);
            
            disco.println(testo);
            
            file.close();
            
        }    catch (IOException ex) {
            return false;
        } 
        return true;
    }
    
}
